package com.jyw.business.obstacles.domain.vo.web;

import cn.hutool.core.date.DateUtil;
import com.jyw.business.obstacles.domain.ObsOrderFault;
import com.jyw.business.obstacles.domain.ObsOrderInfo;
import com.jyw.business.obstacles.domain.ObsOrderMake;
import com.jyw.common.utils.bean.BeanUtils;
import com.jyw.system.utils.ConversionUtil;
import com.jyw.system.utils.FileUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @author 沈峻
 * @ClassName OrderDetailVO
 * @Description TODO
 * @Date 2023/8/16 17:08
 **/
@ApiModel("工单详情实体")
@Data
@NoArgsConstructor
public class OrderDetailVO {

    @ApiModelProperty("报修信息")
    private OrderInfoVO info;

    @ApiModelProperty("故障信息")
    private OrderFaultVO fault;

    @ApiModelProperty("协作信息(子工单)")
    private List<AssistMainVO> assistList;

    @ApiModelProperty("协作信息(主工单)")
    private AssistMainDetailVO assistMain;

    @ApiModelProperty("处理记录")
    private List<MakeProcessVO> makeList;

    @ApiModelProperty("评价信息")
    private OrderEvaluateVO evaluate;

    public OrderDetailVO(ObsOrderInfo info,String ipAddress, ObsOrderFault fault, ObsOrderMake make, List<AssistMainVO> assistList, List<MakeProcessVO> makeProcessVOS, OrderEvaluateVO orderEvaluateVO) {
        if(!ObjectUtils.isEmpty(info)){
            OrderInfoVO vo = new OrderInfoVO();
            BeanUtils.copyProperties(info,vo);
            vo = ConversionUtil.conversion(vo,OrderInfoVO.class);
            vo.setIpAddress(ipAddress);
            setInfo(vo);
        }
        if(!ObjectUtils.isEmpty(fault)){
            OrderFaultVO vo = new OrderFaultVO();
            BeanUtils.copyProperties(fault,vo);
            if(!ObjectUtils.isEmpty(make)){
                vo.setMakeUser(make.getMakeUser());
            }
            vo = ConversionUtil.conversion(vo,OrderFaultVO.class);
            vo.setEnclosure(FileUtils.IdToFile(fault.getEnclosureId()));
            setFault(vo);
        }
        setAssistList(assistList);
        setMakeList(makeProcessVOS);
        setEvaluate(orderEvaluateVO);
    }

    /**
     * 打印工单信息
     */
    public OrderPrintVO buildPrint(){
        OrderPrintVO vo = new OrderPrintVO();
        if(!ObjectUtils.isEmpty(getInfo())){
            vo.setDeptName(getInfo().getDeptName());
            vo.setUser(getInfo().getUser());
            vo.setCreateTimeString(DateUtil.formatDateTime(getInfo().getCreateTime()));
            vo.setPhone(getInfo().getPhone());
        }
        if(!ObjectUtils.isEmpty(getFault())){
            vo.setFaultType(getFault().getFaultType());
            vo.setFaultRemark(getFault().getFaultRemark());
            vo.setDetailInfo("");
            vo.setDegree(getFault().getDegreeToName());
            vo.setRangeType(getFault().getRangeTypeToName());
            vo.setResponseType(getFault().getResponseTypeToName());
        }
        //todo 派单时间,接单时间,处理过程,事件原因,工程师,完成时间
        return vo;
    }
}
